﻿/*--------------------------------------------------------------
 * Author : Shine K Velayudhan 
 ---------------------------------------------------------------*/
using System;

namespace IQN.Logging
{
    public static class ErrorLogExtensions
    {
        private static void log(ILogger logger, Exception error)
        {
            if ((null != logger) && (null != error))
            {
                logger.Log(error);
            }
        }

        public static void LogError(this ILogger logger, Exception error)
        {
            log(logger, error);
        }

        public static void LogError(this ILogger logger, Exception error, string whatHappened)
        {
            if (!string.IsNullOrEmpty(whatHappened))
            {
                error = new Exception(whatHappened, error);
            }
            log(logger, error);
        }

        public static void LogError(this ILogger logger, Exception error, string whatHappened, params object[] args)
        {
            try
            {
                if (!string.IsNullOrEmpty(whatHappened))
                {
                    whatHappened = string.Format(whatHappened, args);
                    error = new Exception(whatHappened, error);
                }
            }
            catch { }
            log(logger, error);
        }
    }
}
